const mongoose = require('mongoose')


// const Schema = mongoose.Schema
//连接数据库
mongoose.connect('mongodb://localhost:27017/react-webapp')

const model = {
    user: {
        'user':{type: String, require: true},
        'pwd':{type: Number, require: true},
        'type':{type: String, require: true},
        //头像
        'avatar': {'type':String},
        //个人简介或者职位介绍
        'desc': {'type':String},
        //职位
        'title': {'type':String},
        //如果你是boss 还有两个额外的字段
        'company': {'type':String},
        'money': {'type':String}
    },
    chat:{

    }
}


//动态生成 model 模型
for(let m in model) {
    mongoose.model(m, new mongoose.Schema(model[m]))
}

module.exports = {
    getModel: function(name){
        return mongoose.model(name)
    }
}

// const userSchema = new Schema({
//     name: {
//         type: String,
//         require: true
//     },
//     password: {
//         type: Number,
//         require: true
//     },
//     age: {
//         type: Number,
//         require: true
//     }
// })

// module.export = mongoose.model('User', userSchema)